<%@ page language="java" contentType="text/xml; charset=utf-8" pageEncoding="utf-8"%><%@ page import="java.sql.*,java.util.Date,java.text.*" %><% 
	
	
	// 사용자 ID 받기
	String userId = request.getParameter("userId");
	if(userId == null ) userId = "";


	// 디비 연결
	Connection conn = null;

	try {
		Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
		//실 테이블
		//conn = DriverManager.getConnection ("jdbc:sqlserver://203.225.1.136:1433;DatabaseName=concise", "sa", "zhsTKdltm@12");

		//개발테이블
		conn = DriverManager.getConnection ("jdbc:sqlserver://203.225.1.136:1433;DatabaseName=concise_test", "concisedev", "devconcise");
	} catch (ClassNotFoundException e) {
		  
		System.out.println("connectDB() 상태 업데이트 DB 접속 오류"+ e.toString());
			throw e;
	} catch (SQLException e) {
		System.out.println("connectDB() 상태 업데이트 DB 접속 오류"+ e.toString());
	
		throw e;
	}

	///////////////////////////////////////////
	// 상세 보기
	//////////////////////////////////////////
	
	 String nMI		     = "-1";

	 StringBuffer query = new StringBuffer();
	 PreparedStatement pstmt = null;
	 ResultSet rs = null;
	 
	 query.append(" Select MI From TB_USER_RIGHT Where USERID = ? ");
	 pstmt = conn.prepareStatement(query.toString());
	 pstmt.setString(1,userId);
	 rs = pstmt.executeQuery();
	  if(rs.next())
		{
		  nMI = nullChk(rs.getString("MI"));
		}

		//MI가 없는 경우 -1 처리
		if(nMI.equals("")) nMI = "-1";

%><?xml version='1.0' encoding='utf-8' ?><NewDataSet>
  <UserInfo>
    <Grade><%=nMI%></Grade>   
  </UserInfo>
</NewDataSet>
<% 
	if(rs != null) try { rs.close(); } catch(SQLException se) {}
	if(pstmt != null) try { pstmt.close(); } catch(SQLException se) {}	
 

////////////////////// DB CLOSE ////////////////////////////
///////////////////////////////////////////////////////////
if(conn != null) {
	try {
		conn.close();
	} catch (Exception e) {
	}
}
conn = null;
///////////////////////////////////////////////////////////
%>  
<%!
	/**
	 * 문자열 NULL 체크 후 NULL일 시 공백으로 반환
	 * @param str	- 문자열
	 * @return
	 */
	public static String nullChk(String str) {
		if(str == null || str.trim().equals("") || "null".equals(str)) return "";
		else return str;
	}
%>